/*
 * utility.c
 *
 *  Created on: 2011/07/25
 *      Author: AKS
 */

#include "app/utility/include/utility.h"
#include "core/include/aks_string.h"

void MemoryDump(DWORD src, DWORD size)
{
	/* dump by block(16bytes) */
	size = size + (src & 0x0000000F);
	size = (size + 0xF) / 0x10;

	src  = src & 0x00FFFFF0;

	/* write header */
    UART_transmitString(UART_DBG, (BYTE*)"      |x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF\r\n");
    UART_transmitString(UART_DBG, (BYTE*)"------+-----------------------------------------------\r\n");

    /* write body */
    BYTE  str[60];
    BYTE *next = str;
	DWORD i=0;
	for(i=0 ; i<size ; ++i)
	{
		next = str;

		next = writeUHex_Fill(src + i*16, 6, next, 60);
		next = write_Str((BYTE*)"|", next, 60);

		DWORD j=0;
		for(j=0 ; j<16 ; ++j)
		{
			BYTE dat = EXTBUS_read(src + i*16 + j);

			next = writeUHex_Fill(dat, 2, next, 60);
			next = write_Str((BYTE*)" ", next, 60);
		}

		next = write_Str((BYTE*)"\r\n", next, 60);

		UART_transmitString(UART_DBG, str);
	}
}
